package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.TravelQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping ("/travel")
public class TravelController {
    @Autowired
    private ITravelService travelService;
    @Autowired
    private IDestinationService destinationService ;
    @RequestMapping ("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo){
        Page<Travel> page = travelService.query(qo);

        model.addAttribute("page",page);
        return  "travel/list";
    }


    ////查看文章
    @RequestMapping ("/getContentById")
    @ResponseBody
    public Object getContentById(String id){
        Travel travel = travelService.get(id);
        return  JsonResult.success(travel.getContent());
    }

    //
    @RequestMapping ("/auditState")
    @ResponseBody
    public Object auditState(String id ,int state){
        travelService.auditState(id,state);
        return  JsonResult.success();//如果成功了,就返回出成功的信息告诉用户,失败就返回获取抛出的异常信息(状态不对)
    }

}
